package com.guli.eduservice.controller;


import com.guli.commonutils.R;
import com.guli.eduservice.bean.EduSubject;
import com.guli.eduservice.bean.subject.OneSubject;
import com.guli.eduservice.service.EduSubjectService;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-04-02
 */
@RestController
@RequestMapping("/eduservice/edusubject")
@CrossOrigin
public class EduSubjectController {
    @Resource
    private EduSubjectService eduSubjectService;

    @PostMapping("addSubject")
    public R addSubject(MultipartFile file){
        Boolean aBoolean = eduSubjectService.saveSubject(file, eduSubjectService);
        if(aBoolean == true){
            return R.ok().message("上传成功");
        }else {
            return R.error().message("上传失败");
        }
    }

    @GetMapping("getSubject")
    public R getSubject(){
        List<OneSubject> allSubject = eduSubjectService.getSubject();
        return R.ok().data("allSubject",allSubject);
    }

    @GetMapping("getAllSubject")
    public R getAllSubject(){
        List<EduSubject> allSubject = eduSubjectService.list(null);
        return R.ok().data("allSubject",allSubject);
    }


}

